home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 242 / Issue 242 - April 2008 - DPCS0408DVD.ISO / Open Source / AutoHotKey / Source / AutoHotkey104705_source.exe / source / defines.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-11-21  |  41.3 KB  |  671 lines

  1. /*
  2. AutoHotkey
  3.  
  4. Copyright 2003-2007 Chris Mallett (support@autohotkey.com)
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15. */
  16.  
  17. #ifndef defines_h
  18. #define defines_h
  19.  
  20. #include "stdafx.h" // pre-compiled headers
  21.  
  22. // Disable silly performance warning about converting int to bool:
  23. // Unlike other typecasts from a larger type to a smaller, I'm 99% sure
  24. // that all compilers are supposed to do something special for bool,
  25. // not just truncate.  Example:
  26. // bool x = 0xF0000000
  27. // The above should give the value "true" to x, not false which is
  28. // what would happen if:
  29. // char x = 0xF0000000
  30. //
  31. #ifdef _MSC_VER
  32. #pragma warning(disable:4800)
  33. #endif
  34.  
  35. #define NAME_P "AutoHotkey"
  36. #define NAME_VERSION "1.0.47.05"
  37. #define NAME_PV NAME_P " v" NAME_VERSION
  38.  
  39. // Window class names: Changing these may result in new versions not being able to detect any old instances
  40. // that may be running (such as the use of FindWindow() in WinMain()).  It may also have other unwanted
  41. // effects, such as anything in the OS that relies on the class name that the user may have changed the
  42. // settings for, such as whether to hide the tray icon (though it probably doesn't use the class name
  43. // in that example).
  44. // MSDN: "Because window classes are process specific, window class names need to be unique only within
  45. // the same process. Also, because class names occupy space in the system's private atom table, you
  46. // should keep class name strings as short a possible:
  47. #define WINDOW_CLASS_MAIN "AutoHotkey"
  48. #define WINDOW_CLASS_SPLASH "AutoHotkey2"
  49. #define WINDOW_CLASS_GUI "AutoHotkeyGUI" // There's a section in Script::Edit() that relies on these all starting with "AutoHotkey".
  50.  
  51. #define EXT_AUTOIT2 ".aut"
  52. #define EXT_AUTOHOTKEY ".ahk"
  53. #define CONVERSION_FLAG (EXT_AUTOIT2 EXT_AUTOHOTKEY)
  54. #define CONVERSION_FLAG_LENGTH 8
  55.  
  56. // AutoIt2 supports lines up to 16384 characters long, and we want to be able to do so too
  57. // so that really long lines from aut2 scripts, such as a chain of IF commands, can be
  58. // brought in and parsed.  In addition, it also allows continuation sections to be long.
  59. #define LINE_SIZE (16384 + 1)  // +1 for terminator.  Don't increase LINE_SIZE above 65535 without considering ArgStruct::length's type (WORD).
  60.  
  61. // The following avoid having to link to OLDNAMES.lib, but they probably don't
  62. // reduce code size at all.
  63. #define stricmp(str1, str2) _stricmp(str1, str2)
  64. #define strnicmp(str1, str2, size) _strnicmp(str1, str2, size)
  65.  
  66. // Items that may be needed for VC++ 6.X:
  67. #ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
  68.     #define SPI_GETFOREGROUNDLOCKTIMEOUT        0x2000
  69.     #define SPI_SETFOREGROUNDLOCKTIMEOUT        0x2001
  70. #endif
  71. #ifndef VK_XBUTTON1
  72.     #define VK_XBUTTON1       0x05    /* NOT contiguous with L & RBUTTON */
  73.     #define VK_XBUTTON2       0x06    /* NOT contiguous with L & RBUTTON */
  74.     #define WM_NCXBUTTONDOWN                0x00AB
  75.     #define WM_NCXBUTTONUP                  0x00AC
  76.     #define WM_NCXBUTTONDBLCLK              0x00AD
  77.     #define GET_WHEEL_DELTA_WPARAM(wParam)  ((short)HIWORD(wParam))
  78.     #define WM_XBUTTONDOWN                  0x020B
  79.     #define WM_XBUTTONUP                    0x020C
  80.     #define WM_XBUTTONDBLCLK                0x020D
  81.     #define GET_KEYSTATE_WPARAM(wParam)     (LOWORD(wParam))
  82.     #define GET_NCHITTEST_WPARAM(wParam)    ((short)LOWORD(wParam))
  83.     #define GET_XBUTTON_WPARAM(wParam)      (HIWORD(wParam))
  84.     /* XButton values are WORD flags */
  85.     #define XBUTTON1      0x0001
  86.     #define XBUTTON2      0x0002
  87. #endif
  88. #ifndef HIMETRIC_INCH
  89.     #define HIMETRIC_INCH 2540
  90. #endif
  91.  
  92.  
  93. #define IS_32BIT(signed_value_64) (signed_value_64 >= INT_MIN && signed_value_64 <= INT_MAX)
  94. #define GET_BIT(buf,n) (((buf) & (1 << (n))) >> (n))
  95. #define SET_BIT(buf,n,val) ((val) ? ((buf) |= (1<<(n))) : (buf &= ~(1<<(n))))
  96.  
  97. // FAIL = 0 to remind that FAIL should have the value zero instead of something arbitrary
  98. // because some callers may simply evaluate the return result as true or false
  99. // (and false is a failure):
  100. enum ResultType {FAIL = 0, OK, WARN = OK, CRITICAL_ERROR  // Some things might rely on OK==1 (i.e. boolean "true")
  101.     , CONDITION_TRUE, CONDITION_FALSE
  102.     , LOOP_BREAK, LOOP_CONTINUE
  103.     , EARLY_RETURN, EARLY_EXIT}; // EARLY_EXIT needs to be distinct from FAIL for ExitApp() and AutoExecSection().
  104.  
  105. enum SendModes {SM_EVENT, SM_INPUT, SM_PLAY, SM_INPUT_FALLBACK_TO_PLAY, SM_INVALID}; // SM_EVENT must be zero.
  106. // In above, SM_INPUT falls back to SM_EVENT when the SendInput mode would be defeated by the presence
  107. // of a keyboard/mouse hooks in another script (it does this because SendEvent is superior to a
  108. // crippled/interruptible SendInput due to SendEvent being able to dynamically adjust to changing
  109. // conditions [such as the user releasing a modifier key during the Send]).  By contrast,
  110. // SM_INPUT_FALLBACK_TO_PLAY falls back to the SendPlay mode.  SendInput has this extra fallback behavior
  111. // because it's likely to become the most popular sending method.
  112.  
  113. enum ExitReasons {EXIT_NONE, EXIT_CRITICAL, EXIT_ERROR, EXIT_DESTROY, EXIT_LOGOFF, EXIT_SHUTDOWN
  114.     , EXIT_WM_QUIT, EXIT_WM_CLOSE, EXIT_MENU, EXIT_EXIT, EXIT_RELOAD, EXIT_SINGLEINSTANCE};
  115.  
  116. enum SingleInstanceType {ALLOW_MULTI_INSTANCE, SINGLE_INSTANCE_PROMPT, SINGLE_INSTANCE_REPLACE
  117.     , SINGLE_INSTANCE_IGNORE, SINGLE_INSTANCE_OFF}; // ALLOW_MULTI_INSTANCE must be zero.
  118.  
  119. enum MenuTypeType {MENU_TYPE_NONE, MENU_TYPE_POPUP, MENU_TYPE_BAR}; // NONE must be zero.
  120.  
  121. // These are used for things that can be turned on, off, or left at a
  122. // neutral default value that is neither on nor off.  INVALID must
  123. // be zero:
  124. enum ToggleValueType {TOGGLE_INVALID = 0, TOGGLED_ON, TOGGLED_OFF, ALWAYS_ON, ALWAYS_OFF, TOGGLE
  125.     , TOGGLE_PERMIT, NEUTRAL, TOGGLE_SEND, TOGGLE_MOUSE, TOGGLE_SENDANDMOUSE, TOGGLE_DEFAULT
  126.     , TOGGLE_MOUSEMOVE, TOGGLE_MOUSEMOVEOFF};
  127.  
  128. // Some things (such as ListView sorting) rely on SCS_INSENSITIVE being zero.
  129. // In addition, BIF_InStr relies on SCS_SENSITIVE being 1:
  130. enum StringCaseSenseType {SCS_INSENSITIVE, SCS_SENSITIVE, SCS_INSENSITIVE_LOCALE, SCS_INSENSITIVE_LOGICAL, SCS_INVALID};
  131.  
  132. enum SymbolType // For use with ExpandExpression() and IsPureNumeric().
  133. {
  134.     // The sPrecedence array in ExpandExpression() must be kept in sync with any additions, removals,
  135.     // or re-ordering of the below.  Also, IS_OPERAND() relies on all operand types being at the
  136.     // beginning of the list:
  137.      PURE_NOT_NUMERIC // Must be zero/false because callers rely on that.
  138.     , PURE_INTEGER, PURE_FLOAT
  139.     , SYM_STRING = PURE_NOT_NUMERIC, SYM_INTEGER = PURE_INTEGER, SYM_FLOAT = PURE_FLOAT // Specific operand types.
  140. #define IS_NUMERIC(symbol) ((symbol) == SYM_INTEGER || (symbol) == SYM_FLOAT) // Ordered for short-circuit performance.
  141.     , SYM_VAR // An operand that is a variable's contents.
  142.     , SYM_OPERAND // Generic/undetermined type of operand.
  143.     , SYM_DYNAMIC // An operand that needs further processing during the evaluation phase.
  144.     , SYM_OPERAND_END // Marks the symbol after the last operand.  This value is used below.
  145.     , SYM_BEGIN = SYM_OPERAND_END  // SYM_BEGIN is a special marker to simplify the code.
  146. #define IS_OPERAND(symbol) ((symbol) < SYM_OPERAND_END)
  147.     , SYM_POST_INCREMENT, SYM_POST_DECREMENT // Kept in this position for use by YIELDS_AN_OPERAND() [helps performance].
  148.     , SYM_CPAREN, SYM_OPAREN, SYM_COMMA  // CPAREN (close-paren) must come right before OPAREN and must be the first non-operand symbol other than SYM_BEGIN.
  149. #define YIELDS_AN_OPERAND(symbol) ((symbol) < SYM_OPAREN) // CPAREN also covers the tail end of a function call.  Post-inc/dec yields an operand for things like Var++ + 2.  Definitely needs the parentheses around symbol.
  150.     , SYM_ASSIGN, SYM_ASSIGN_ADD, SYM_ASSIGN_SUBTRACT, SYM_ASSIGN_MULTIPLY, SYM_ASSIGN_DIVIDE, SYM_ASSIGN_FLOORDIVIDE
  151.     , SYM_ASSIGN_BITOR, SYM_ASSIGN_BITXOR, SYM_ASSIGN_BITAND, SYM_ASSIGN_BITSHIFTLEFT, SYM_ASSIGN_BITSHIFTRIGHT
  152.     , SYM_ASSIGN_CONCAT // THIS MUST BE KEPT AS THE LAST (AND SYM_ASSIGN THE FIRST) BECAUSE THEY'RE USED IN A RANGE-CHECK.
  153. #define IS_ASSIGNMENT_EXCEPT_POST_AND_PRE(symbol) (symbol <= SYM_ASSIGN_CONCAT && symbol >= SYM_ASSIGN) // Check upper bound first for short-circuit performance.
  154. #define IS_ASSIGNMENT_OR_POST_OP(symbol) (IS_ASSIGNMENT_EXCEPT_POST_AND_PRE(symbol) || symbol == SYM_POST_INCREMENT || symbol == SYM_POST_DECREMENT)
  155.     , SYM_IFF_ELSE, SYM_IFF_THEN // THESE TERNARY OPERATORS MUST BE KEPT IN THIS ORDER AND ADJACENT TO THE BELOW.
  156.     , SYM_OR, SYM_AND // MUST BE KEPT IN THIS ORDER AND ADJACENT TO THE ABOVE because infix-to-postfix is optimized to check a range rather than a series of equalities.
  157.     , SYM_LOWNOT  // LOWNOT is the word "not", the low precedence counterpart of !
  158.     , SYM_EQUAL, SYM_EQUALCASE, SYM_NOTEQUAL // =, ==, <> ... Keep this in sync with IS_RELATIONAL_OPERATOR() below.
  159.     , SYM_GT, SYM_LT, SYM_GTOE, SYM_LTOE  // >, <, >=, <= ... Keep this in sync with IS_RELATIONAL_OPERATOR() below.
  160. #define IS_RELATIONAL_OPERATOR(symbol) (symbol >= SYM_EQUAL && symbol <= SYM_LTOE)
  161.     , SYM_CONCAT
  162.     , SYM_BITOR // Seems more intuitive to have these higher in prec. than the above, unlike C and Perl, but like Python.
  163.     , SYM_BITXOR // SYM_BITOR (ABOVE) MUST BE KEPT FIRST AMONG THE BIT OPERATORS BECAUSE IT'S USED IN A RANGE-CHECK.
  164.     , SYM_BITAND
  165.     , SYM_BITSHIFTLEFT, SYM_BITSHIFTRIGHT // << >>  ALSO: SYM_BITSHIFTRIGHT MUST BE KEPT LAST AMONG THE BIT OPERATORS BECAUSE IT'S USED IN A RANGE-CHECK.
  166.     , SYM_ADD, SYM_SUBTRACT
  167.     , SYM_MULTIPLY, SYM_DIVIDE, SYM_FLOORDIVIDE
  168.     , SYM_NEGATIVE, SYM_HIGHNOT, SYM_BITNOT, SYM_ADDRESS, SYM_DEREF  // Don't change position or order of these because Infix-to-postfix converter's special handling for SYM_POWER relies on them being adjacent to each other.
  169.     , SYM_POWER    // See comments near precedence array for why this takes precedence over SYM_NEGATIVE.
  170.     , SYM_PRE_INCREMENT, SYM_PRE_DECREMENT // Must be kept after the post-ops and in this order relative to each other due to a range check in the code.
  171.     , SYM_FUNC     // A call to a function.
  172.     , SYM_COUNT    // Must be last because it's the total symbol count for everything above.
  173.     , SYM_INVALID = SYM_COUNT // Some callers may rely on YIELDS_AN_OPERAND(SYM_INVALID)==false.
  174. };
  175. // These two are macros for maintainability (i.e. seeing them together here helps maintain them together).
  176. #define SYM_DYNAMIC_IS_DOUBLE_DEREF(token) (token.buf) // SYM_DYNAMICs other than doubles have NULL buf, at least at the stage this macro is called.
  177. #define SYM_DYNAMIC_IS_VAR_NORMAL_OR_CLIP(token) (!(token)->buf && ((token)->var->Type() == VAR_NORMAL || (token)->var->Type() == VAR_CLIPBOARD)) // i.e. it's an evironment variable or the clipboard, not a built-in variable or double-deref.
  178.  
  179. struct DerefType; // Forward declarations for use below.
  180. class Var;        //
  181. struct ExprTokenType  // Something in the compiler hates the name TokenType, so using a different name.
  182. {
  183.     // Due to the presence of 8-byte members (double and __int64) this entire struct is aligned on 8-byte
  184.     // vs. 4-byte boundaries.  The compiler defaults to this because otherwise an 8-byte member might
  185.     // sometimes not start at an even address, which would hurt performance on Pentiums, etc.
  186.     union // Which of its members is used depends on the value of symbol, below.
  187.     {
  188.         __int64 value_int64; // for SYM_INTEGER
  189.         double value_double; // for SYM_FLOAT
  190.         struct
  191.         {
  192.             union // These nested structs and unions minimize the token size by overlapping data.
  193.             {
  194.                 DerefType *deref; // for SYM_FUNC
  195.                 Var *var;         // for SYM_VAR
  196.                 char *marker;     // for SYM_STRING and SYM_OPERAND.
  197.             };
  198.             char *buf; // This doesn't increase the total size of the struct. It's used by built-in functions and perhaps other misc. purposes.
  199.         };  
  200.     };
  201.     // Note that marker's str-length should not be stored in this struct, even though it might be readily
  202.     // available in places and thus help performance.  This is because if it were stored and the marker
  203.     // or SYM_VAR's var pointed to a location that was changed as a side effect of an expression's
  204.     // call to a script function, the length would then be invalid.
  205.     SymbolType symbol; // Short-circuit benchmark is currently much faster with this and the next beneath the union, perhaps due to CPU optimizations for 8-byte alignment.
  206.     ExprTokenType *circuit_token; // Facilitates short-circuit boolean evaluation.
  207.     // The above two probably need to be adjacent to each other to conserve memory due to 8-byte alignment,
  208.     // which is the default alignment (for performance reasons) in any struct that contains 8-byte members
  209.     // such as double and __int64.
  210. };
  211.  
  212. // But the array that goes with these actions is in globaldata.cpp because
  213. // otherwise it would be a little cumbersome to declare the extern version
  214. // of the array in here (since it's only extern to modules other than
  215. // script.cpp):
  216. enum enum_act {
  217. // Seems best to make ACT_INVALID zero so that it will be the ZeroMemory() default within
  218. // any POD structures that contain an action_type field:
  219.   ACT_INVALID = FAIL  // These should both be zero for initialization and function-return-value purposes.
  220. , ACT_ASSIGN, ACT_ASSIGNEXPR, ACT_EXPRESSION, ACT_ADD, ACT_SUB, ACT_MULT, ACT_DIV
  221. , ACT_ASSIGN_FIRST = ACT_ASSIGN, ACT_ASSIGN_LAST = ACT_DIV
  222. , ACT_REPEAT // Never parsed directly, only provided as a translation target for the old command (see other notes).
  223. , ACT_ELSE   // Parsed at a lower level than most commands to support same-line ELSE-actions (e.g. "else if").
  224. , ACT_IFBETWEEN, ACT_IFNOTBETWEEN, ACT_IFIN, ACT_IFNOTIN, ACT_IFCONTAINS, ACT_IFNOTCONTAINS, ACT_IFIS, ACT_IFISNOT
  225. , ACT_IFEXPR  // i.e. if (expr)
  226.  // *** *** *** KEEP ALL OLD-STYLE/AUTOIT V2 IFs AFTER THIS (v1.0.20 bug fix). *** *** ***
  227.  , ACT_FIRST_IF_ALLOWING_SAME_LINE_ACTION
  228.  // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
  229.  // ACT_IS_IF_OLD() relies upon ACT_IFEQUAL through ACT_IFLESSOREQUAL being adjacent to one another
  230.  // and it relies upon the fact that ACT_IFEQUAL is first in the series and ACT_IFLESSOREQUAL last.
  231. , ACT_IFEQUAL = ACT_FIRST_IF_ALLOWING_SAME_LINE_ACTION, ACT_IFNOTEQUAL, ACT_IFGREATER, ACT_IFGREATEROREQUAL
  232. , ACT_IFLESS, ACT_IFLESSOREQUAL
  233. , ACT_FIRST_COMMAND // i.e the above aren't considered commands for parsing/searching purposes.
  234. , ACT_IFWINEXIST = ACT_FIRST_COMMAND
  235. , ACT_IFWINNOTEXIST, ACT_IFWINACTIVE, ACT_IFWINNOTACTIVE
  236. , ACT_IFINSTRING, ACT_IFNOTINSTRING
  237. , ACT_IFEXIST, ACT_IFNOTEXIST, ACT_IFMSGBOX
  238. , ACT_FIRST_IF = ACT_IFBETWEEN, ACT_LAST_IF = ACT_IFMSGBOX  // Keep this range updated with any new IFs that are added.
  239. , ACT_MSGBOX, ACT_INPUTBOX, ACT_SPLASHTEXTON, ACT_SPLASHTEXTOFF, ACT_PROGRESS, ACT_SPLASHIMAGE
  240. , ACT_TOOLTIP, ACT_TRAYTIP, ACT_INPUT
  241. , ACT_TRANSFORM, ACT_STRINGLEFT, ACT_STRINGRIGHT, ACT_STRINGMID
  242. , ACT_STRINGTRIMLEFT, ACT_STRINGTRIMRIGHT, ACT_STRINGLOWER, ACT_STRINGUPPER
  243. , ACT_STRINGLEN, ACT_STRINGGETPOS, ACT_STRINGREPLACE, ACT_STRINGSPLIT, ACT_SPLITPATH, ACT_SORT
  244. , ACT_ENVGET, ACT_ENVSET, ACT_ENVUPDATE
  245. , ACT_RUNAS, ACT_RUN, ACT_RUNWAIT, ACT_URLDOWNLOADTOFILE
  246. , ACT_GETKEYSTATE
  247. , ACT_SEND, ACT_SENDRAW, ACT_SENDINPUT, ACT_SENDPLAY, ACT_SENDEVENT
  248. , ACT_CONTROLSEND, ACT_CONTROLSENDRAW, ACT_CONTROLCLICK, ACT_CONTROLMOVE, ACT_CONTROLGETPOS, ACT_CONTROLFOCUS
  249. , ACT_CONTROLGETFOCUS, ACT_CONTROLSETTEXT, ACT_CONTROLGETTEXT, ACT_CONTROL, ACT_CONTROLGET
  250. , ACT_SENDMODE, ACT_COORDMODE, ACT_SETDEFAULTMOUSESPEED
  251. , ACT_CLICK, ACT_MOUSEMOVE, ACT_MOUSECLICK, ACT_MOUSECLICKDRAG, ACT_MOUSEGETPOS
  252. , ACT_STATUSBARGETTEXT
  253. , ACT_STATUSBARWAIT
  254. , ACT_CLIPWAIT, ACT_KEYWAIT
  255. , ACT_SLEEP, ACT_RANDOM
  256. , ACT_GOTO, ACT_GOSUB, ACT_ONEXIT, ACT_HOTKEY, ACT_SETTIMER, ACT_CRITICAL, ACT_THREAD, ACT_RETURN, ACT_EXIT
  257. , ACT_LOOP, ACT_BREAK, ACT_CONTINUE
  258. , ACT_BLOCK_BEGIN, ACT_BLOCK_END
  259. , ACT_WINACTIVATE, ACT_WINACTIVATEBOTTOM
  260. , ACT_WINWAIT, ACT_WINWAITCLOSE, ACT_WINWAITACTIVE, ACT_WINWAITNOTACTIVE
  261. , ACT_WINMINIMIZE, ACT_WINMAXIMIZE, ACT_WINRESTORE
  262. , ACT_WINHIDE, ACT_WINSHOW
  263. , ACT_WINMINIMIZEALL, ACT_WINMINIMIZEALLUNDO
  264. , ACT_WINCLOSE, ACT_WINKILL, ACT_WINMOVE, ACT_WINMENUSELECTITEM, ACT_PROCESS
  265. , ACT_WINSET, ACT_WINSETTITLE, ACT_WINGETTITLE, ACT_WINGETCLASS, ACT_WINGET, ACT_WINGETPOS, ACT_WINGETTEXT
  266. , ACT_SYSGET, ACT_POSTMESSAGE, ACT_SENDMESSAGE
  267. // Keep rarely used actions near the bottom for parsing/performance reasons:
  268. , ACT_PIXELGETCOLOR, ACT_PIXELSEARCH, ACT_IMAGESEARCH
  269. , ACT_GROUPADD, ACT_GROUPACTIVATE, ACT_GROUPDEACTIVATE, ACT_GROUPCLOSE
  270. , ACT_DRIVESPACEFREE, ACT_DRIVE, ACT_DRIVEGET
  271. , ACT_SOUNDGET, ACT_SOUNDSET, ACT_SOUNDGETWAVEVOLUME, ACT_SOUNDSETWAVEVOLUME, ACT_SOUNDBEEP, ACT_SOUNDPLAY
  272. , ACT_FILEAPPEND, ACT_FILEREAD, ACT_FILEREADLINE, ACT_FILEDELETE, ACT_FILERECYCLE, ACT_FILERECYCLEEMPTY
  273. , ACT_FILEINSTALL, ACT_FILECOPY, ACT_FILEMOVE, ACT_FILECOPYDIR, ACT_FILEMOVEDIR
  274. , ACT_FILECREATEDIR, ACT_FILEREMOVEDIR
  275. , ACT_FILEGETATTRIB, ACT_FILESETATTRIB, ACT_FILEGETTIME, ACT_FILESETTIME
  276. , ACT_FILEGETSIZE, ACT_FILEGETVERSION
  277. , ACT_SETWORKINGDIR, ACT_FILESELECTFILE, ACT_FILESELECTFOLDER, ACT_FILEGETSHORTCUT, ACT_FILECREATESHORTCUT
  278. , ACT_INIREAD, ACT_INIWRITE, ACT_INIDELETE
  279. , ACT_REGREAD, ACT_REGWRITE, ACT_REGDELETE, ACT_OUTPUTDEBUG
  280. , ACT_SETKEYDELAY, ACT_SETMOUSEDELAY, ACT_SETWINDELAY, ACT_SETCONTROLDELAY, ACT_SETBATCHLINES
  281. , ACT_SETTITLEMATCHMODE, ACT_SETFORMAT, ACT_FORMATTIME
  282. , ACT_SUSPEND, ACT_PAUSE
  283. , ACT_AUTOTRIM, ACT_STRINGCASESENSE, ACT_DETECTHIDDENWINDOWS, ACT_DETECTHIDDENTEXT, ACT_BLOCKINPUT
  284. , ACT_SETNUMLOCKSTATE, ACT_SETSCROLLLOCKSTATE, ACT_SETCAPSLOCKSTATE, ACT_SETSTORECAPSLOCKMODE
  285. , ACT_KEYHISTORY, ACT_LISTLINES, ACT_LISTVARS, ACT_LISTHOTKEYS
  286. , ACT_EDIT, ACT_RELOAD, ACT_MENU, ACT_GUI, ACT_GUICONTROL, ACT_GUICONTROLGET
  287. , ACT_EXITAPP
  288. , ACT_SHUTDOWN
  289. // Make these the last ones before the count so they will be less often processed.  This helps
  290. // performance because this one doesn't actually have a keyword so will never result
  291. // in a match anyway.  UPDATE: No longer used because Run/RunWait is now required, which greatly
  292. // improves syntax checking during load:
  293. //, ACT_EXEC
  294. // It's safer not to do this here.  It's better set by a
  295. // calculation immediately after the array is declared and initialized,
  296. // at which time we know its true size:
  297. // , ACT_COUNT
  298. };
  299.  
  300. enum enum_act_old {
  301.   OLD_INVALID = FAIL  // These should both be zero for initialization and function-return-value purposes.
  302.   , OLD_SETENV, OLD_ENVADD, OLD_ENVSUB, OLD_ENVMULT, OLD_ENVDIV
  303.   // ACT_IS_IF_OLD() relies on the items in this next line being adjacent to one another and in this order:
  304.   , OLD_IFEQUAL, OLD_IFNOTEQUAL, OLD_IFGREATER, OLD_IFGREATEROREQUAL, OLD_IFLESS, OLD_IFLESSOREQUAL
  305.   , OLD_LEFTCLICK, OLD_RIGHTCLICK, OLD_LEFTCLICKDRAG, OLD_RIGHTCLICKDRAG
  306.   , OLD_HIDEAUTOITWIN, OLD_REPEAT, OLD_ENDREPEAT
  307.   , OLD_WINGETACTIVETITLE, OLD_WINGETACTIVESTATS
  308. };
  309.  
  310. // It seems best not to include ACT_SUSPEND in the below, since the user may have marked
  311. // a large number of subroutines as "Suspend, Permit".  Even PAUSE is iffy, since the user
  312. // may be using it as "Pause, off/toggle", but it seems best to support PAUSE because otherwise
  313. // hotkey such as "#z::pause" would not be able to unpause the script if its MaxThreadsPerHotkey
  314. // was 1 (the default).
  315. #define ACT_IS_ALWAYS_ALLOWED(ActionType) (ActionType == ACT_EXITAPP || ActionType == ACT_PAUSE \
  316.     || ActionType == ACT_EDIT || ActionType == ACT_RELOAD || ActionType == ACT_KEYHISTORY \
  317.     || ActionType == ACT_LISTLINES || ActionType == ACT_LISTVARS || ActionType == ACT_LISTHOTKEYS)
  318. #define ACT_IS_ASSIGN(ActionType) (ActionType >= ACT_ASSIGN_FIRST && ActionType <= ACT_ASSIGN_LAST)
  319. #define ACT_IS_IF(ActionType) (ActionType >= ACT_FIRST_IF && ActionType <= ACT_LAST_IF)
  320. #define ACT_IS_IF_OR_ELSE_OR_LOOP(ActionType) (ACT_IS_IF(ActionType) || ActionType == ACT_ELSE || ActionType == ACT_LOOP)
  321. #define ACT_IS_IF_OLD(ActionType, OldActionType) (ActionType >= ACT_FIRST_IF_ALLOWING_SAME_LINE_ACTION && ActionType <= ACT_LAST_IF) \
  322.     && (ActionType < ACT_IFEQUAL || ActionType > ACT_IFLESSOREQUAL || (OldActionType >= OLD_IFEQUAL && OldActionType <= OLD_IFLESSOREQUAL))
  323.     // All the checks above must be done so that cmds such as IfMsgBox (which are both "old" and "new")
  324.     // can support parameters on the same line or on the next line.  For example, both of the above are allowed:
  325.     // IfMsgBox, No, Gosub, XXX
  326.     // IfMsgBox, No
  327.     //     Gosub, XXX
  328.  
  329. // For convenience in many places.  Must cast to int to avoid loss of negative values.
  330. #define BUF_SPACE_REMAINING ((int)(aBufSize - (aBuf - aBuf_orig)))
  331.  
  332. // MsgBox timeout value.  This can't be zero because that is used as a failure indicator:
  333. // Also, this define is in this file to prevent problems with mutual
  334. // dependency between script.h and window.h.  Update: It can't be -1 either because
  335. // that value is used to indicate failure by DialogBox():
  336. #define AHK_TIMEOUT -2
  337. // And these to prevent mutual dependency problem between window.h and globaldata.h:
  338. #define MAX_MSGBOXES 7
  339. #define MAX_INPUTBOXES 4
  340. #define MAX_PROGRESS_WINDOWS 10  // Allow a lot for downloads and such.
  341. #define MAX_PROGRESS_WINDOWS_STR "10" // Keep this in sync with above.
  342. #define MAX_SPLASHIMAGE_WINDOWS 10
  343. #define MAX_SPLASHIMAGE_WINDOWS_STR "10" // Keep this in sync with above.
  344. #define MAX_GUI_WINDOWS 99  // Things that parse the "NN:" prefix for Gui/GuiControl might rely on this being 2-digit.
  345. #define MAX_GUI_WINDOWS_STR "99" // Keep this in sync with above.
  346. #define MAX_MSG_MONITORS 500
  347.  
  348. // IMPORTANT: Before ever changing the below, note that it will impact the IDs of menu items created
  349. // with the MENU command, as well as the number of such menu items that are possible (currently about
  350. // 65500-11000=54500). See comments at ID_USER_FIRST for details:
  351. #define GUI_CONTROL_BLOCK_SIZE 1000
  352. #define MAX_CONTROLS_PER_GUI (GUI_CONTROL_BLOCK_SIZE * 11) // Some things rely on this being less than 0xFFFF and an even multiple of GUI_CONTROL_BLOCK_SIZE.
  353. #define NO_CONTROL_INDEX MAX_CONTROLS_PER_GUI // Must be 0xFFFF or less.
  354. #define NO_EVENT_INFO 0 // For backward compatibility with documented contents of A_EventInfo, this should be kept as 0 vs. something more special like UINT_MAX.
  355.  
  356. #define MAX_TOOLTIPS 20
  357. #define MAX_TOOLTIPS_STR "20"   // Keep this in sync with above.
  358. #define MAX_FILEDIALOGS 4
  359. #define MAX_FOLDERDIALOGS 4
  360. #define MAX_NUMBER_LENGTH 20
  361. #define MAX_NUMBER_SIZE (MAX_NUMBER_LENGTH + 1)
  362. // Above is the maximum length of a 64-bit number when expressed as decimal or hex string.
  363. // e.g. -9223372036854775808 or (unsigned) 18446744073709551616
  364.  
  365. // Hot-strings:
  366. // memmove() and proper detection of long hotstrings rely on buf being at least this large:
  367. #define HS_BUF_SIZE (MAX_HOTSTRING_LENGTH * 2 + 10)
  368. #define HS_BUF_DELETE_COUNT (HS_BUF_SIZE / 2)
  369. #define HS_MAX_END_CHARS 100
  370.  
  371. // Bitwise storage of boolean flags.  This section is kept in this file because
  372. // of mutual dependency problems between hook.h and other header files:
  373. typedef UCHAR HookType;
  374. #define HOOK_KEYBD 0x01
  375. #define HOOK_MOUSE 0x02
  376. #define HOOK_FAIL  0xFF
  377.  
  378. #define EXTERN_G extern global_struct g
  379. #define EXTERN_OSVER extern OS_Version g_os
  380. #define EXTERN_CLIPBOARD extern Clipboard g_clip
  381. #define EXTERN_SCRIPT extern Script g_script
  382. #define CLOSE_CLIPBOARD_IF_OPEN    if (g_clip.mIsOpen) g_clip.Close()
  383. #define CLIPBOARD_CONTAINS_ONLY_FILES (!IsClipboardFormatAvailable(CF_TEXT) && IsClipboardFormatAvailable(CF_HDROP))
  384.  
  385.  
  386. // These macros used to keep app responsive during a long operation.  In v1.0.39, the
  387. // hooks have a dedicated thread.  However, mLastPeekTime is still compared to 5 rather
  388. // than some higher value for the following reasons:
  389. // 1) Want hotkeys pressed during a long operation to take effect as quickly as possible.
  390. //    For example, in games a hotkey's response time is critical.
  391. // 2) Benchmarking shows less than a 0.5% performance improvement from this comparing
  392. //    to a higher value (even one as high as 500), even when the system is under heavy
  393. //    load from other processes).
  394. //
  395. // mLastPeekTime is global/static so that recursive functions, such as FileSetAttrib(),
  396. // will sleep as often as intended even if the target files require frequent recursion.
  397. // The use of a global/static is not friendly to recursive calls to the function (i.e. calls
  398. // maded as a consequence of the current script subroutine being interrupted by another during
  399. // this instance's MsgSleep()).  However, it doesn't seem to be that much of a consequence
  400. // since the exact interval/period of the MsgSleep()'s isn't that important.  It's also
  401. // pretty unlikely that the interrupting subroutine will also just happen to call the same
  402. // function rather than some other.
  403. //
  404. // Older comment that applies if there is ever again no dedicated thread for the hooks:
  405. // These macros were greatly simplified when it was discovered that PeekMessage(), when called
  406. // directly as below, is enough to prevent keyboard and mouse lag when the hooks are installed
  407. #define LONG_OPERATION_INIT MSG msg; DWORD tick_now;
  408.  
  409. // MsgSleep() is used rather than SLEEP_WITHOUT_INTERRUPTION to allow other hotkeys to
  410. // launch and interrupt (suspend) the operation.  It seems best to allow that, since
  411. // the user may want to press some fast window activation hotkeys, for example, during
  412. // the operation.  The operation will be resumed after the interrupting subroutine finishes.
  413. // Notes applying to the macro:
  414. // Store tick_now for use later, in case the Peek() isn't done, though not all callers need it later.
  415. // ...
  416. // Since the Peek() will yield when there are no messages, it will often take 20ms or more to return
  417. // (UPDATE: this can't be reproduced with simple tests, so either the OS has changed through service
  418. // packs, or Peek() yields only when the OS detects that the app is calling it too often or calling
  419. // it in certain ways [PM_REMOVE vs. PM_NOREMOVE seems to make no differnce: either way it doesn't yield]).
  420. // Therefore, must update tick_now again (its value is used by macro and possibly by its caller)
  421. // to avoid having to Peek() immediately after the next iteration.
  422. // ...
  423. // The code might bench faster when "g_script.mLastPeekTime = tick_now" is a separate operation rather
  424. // than combined in a chained assignment statement.
  425. #define LONG_OPERATION_UPDATE \
  426. {\
  427.     tick_now = GetTickCount();\
  428.     if (tick_now - g_script.mLastPeekTime > g.PeekFrequency)\
  429.     {\
  430.         if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))\
  431.             MsgSleep(-1);\
  432.         tick_now = GetTickCount();\
  433.         g_script.mLastPeekTime = tick_now;\
  434.     }\
  435. }
  436.  
  437. // Same as the above except for SendKeys() and related functions (uses SLEEP_WITHOUT_INTERRUPTION vs. MsgSleep).
  438. #define LONG_OPERATION_UPDATE_FOR_SENDKEYS \
  439. {\
  440.     tick_now = GetTickCount();\
  441.     if (tick_now - g_script.mLastPeekTime > g.PeekFrequency)\
  442.     {\
  443.         if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))\
  444.             SLEEP_WITHOUT_INTERRUPTION(-1) \
  445.         tick_now = GetTickCount();\
  446.         g_script.mLastPeekTime = tick_now;\
  447.     }\
  448. }
  449.  
  450. // Defining these here avoids awkwardness due to the fact that globaldata.cpp
  451. // does not (for design reasons) include globaldata.h:
  452. typedef UCHAR ActionTypeType; // If ever have more than 256 actions, will have to change this (but it would increase code size due to static data in g_act).
  453. #pragma pack(1) // v1.0.45: Reduces code size a little without impacting runtime performance because this struct is hardly ever accessed during runtime.
  454. struct Action
  455. {
  456.     char *Name;
  457.     // Just make them int's, rather than something smaller, because the collection
  458.     // of actions will take up very little memory.  Int's are probably faster
  459.     // for the processor to access since they are the native word size, or something:
  460.     // Update for v1.0.40.02: Now that the ARGn macros don't check mArgc, MaxParamsAu2WithHighBit
  461.     // is needed to allow MaxParams to stay pure, which in turn prevents Line::Perform()
  462.     // from accessing a NULL arg in the sArgDeref array (i.e. an arg that exists only for
  463.     // non-AutoIt2 scripts, such as the extra ones in StringGetPos).
  464.     // Also, changing these from ints to chars greatly reduces code size since this struct
  465.     // is used by g_act to build static data into the code.  Testing shows that the compiler
  466.     // will generate a warning even when not in debug mode in the unlikely event that a constant
  467.     // larger than 127 is ever stored in one of these:
  468.     char MinParams, MaxParams, MaxParamsAu2WithHighBit;
  469.     // Array indicating which args must be purely numeric.  The first arg is
  470.     // number 1, the second 2, etc (i.e. it doesn't start at zero).  The list
  471.     // is ended with a zero, much like a string.  The compiler will notify us
  472.     // (verified) if MAX_NUMERIC_PARAMS ever needs to be increased:
  473.     #define MAX_NUMERIC_PARAMS 7
  474.     ActionTypeType NumericParams[MAX_NUMERIC_PARAMS];
  475. };
  476. #pragma pack()  // Calling pack with no arguments restores the default value (which is 8, but "the alignment of a member will be on a boundary that is either a multiple of n or a multiple of the size of the member, whichever is smaller.")
  477.  
  478. // Values are hard-coded for some of the below because they must not deviate from the documented, numerical
  479. // TitleMatchModes:
  480. enum TitleMatchModes {MATCHMODE_INVALID = FAIL, FIND_IN_LEADING_PART = 1, FIND_ANYWHERE = 2, FIND_EXACT = 3, FIND_REGEX, FIND_FAST, FIND_SLOW};
  481.  
  482. typedef UINT GuiIndexType; // Some things rely on it being unsigned to avoid the need to check for less-than-zero.
  483. typedef UINT GuiEventType; // Made a UINT vs. enum so that illegal/underflow/overflow values are easier to detect.
  484.  
  485. // The following array and enum must be kept in sync with each other:
  486. #define GUI_EVENT_NAMES {"", "Normal", "DoubleClick", "RightClick", "ColClick"}
  487. enum GuiEventTypes {GUI_EVENT_NONE  // NONE must be zero for any uses of ZeroMemory(), synonymous with false, etc.
  488.     , GUI_EVENT_NORMAL, GUI_EVENT_DBLCLK // Try to avoid changing this and the other common ones in case anyone automates a script via SendMessage (though that does seem very unlikely).
  489.     , GUI_EVENT_RCLK, GUI_EVENT_COLCLK
  490.     , GUI_EVENT_FIRST_UNNAMED  // This item must always be 1 greater than the last item that has a name in the GUI_EVENT_NAMES array below.
  491.     , GUI_EVENT_DROPFILES = GUI_EVENT_FIRST_UNNAMED
  492.     , GUI_EVENT_CLOSE, GUI_EVENT_ESCAPE, GUI_EVENT_RESIZE, GUI_EVENT_CONTEXTMENU
  493.     , GUI_EVENT_DIGIT_0 = 48}; // Here just as a reminder that this value and higher are reserved so that a single printable character or digit (mnemonic) can be sent, and also so that ListView's "I" notification can add extra data into the high-byte (which lies just to the left of the "I" character in the bitfield).
  494.  
  495. // Bitwise flags:
  496. typedef UCHAR CoordModeAttribType;
  497. #define COORD_MODE_PIXEL   0x01
  498. #define COORD_MODE_MOUSE   0x02
  499. #define COORD_MODE_TOOLTIP 0x04
  500. #define COORD_MODE_CARET   0x08
  501. #define COORD_MODE_MENU    0x10
  502.  
  503. #define COORD_CENTERED (INT_MIN + 1)
  504. #define COORD_UNSPECIFIED INT_MIN
  505. #define COORD_UNSPECIFIED_SHORT SHRT_MIN  // This essentially makes coord -32768 "reserved", but it seems acceptable given usefulness and the rarity of a real coord like that.
  506.  
  507. // Same reason as above struct.  It's best to keep this struct as small as possible
  508. // because it's used as a local (stack) var by at least one recursive function:
  509. // Each instance of this struct generally corresponds to a quasi-thread.  The function that creates
  510. // a new thread typically saves the old thread's struct values on its stack so that they can later
  511. // be copied back into the g struct when the thread is resumed:
  512. class Func;                 // Forward declarations
  513. class Label;                //
  514. struct RegItemStruct;       //
  515. struct LoopReadFileStruct;  //
  516. struct global_struct
  517. {
  518.     // 8-byte items are listed first, which might improve alignment for 64-bit processors (dubious).
  519.     __int64 LinesPerCycle; // Use 64-bits for this so that user can specify really large values.
  520.     __int64 mLoopIteration; // Signed, since script/ITOA64 aren't designed to handle unsigned.
  521.     WIN32_FIND_DATA *mLoopFile;  // The file of the current file-loop, if applicable.
  522.     RegItemStruct *mLoopRegItem; // The registry subkey or value of the current registry enumeration loop.
  523.     LoopReadFileStruct *mLoopReadFile;  // The file whose contents are currently being read by a File-Read Loop.
  524.     char *mLoopField;  // The field of the current string-parsing loop.
  525.     // v1.0.44.14: The above mLoop attributes were moved into this structure from the script class
  526.     // because they're more approriate as thread-attributes rather than being global to the entire script.
  527.  
  528.     TitleMatchModes TitleMatchMode;
  529.     int IntervalBeforeRest;
  530.     int UninterruptedLineCount; // Stored as a g-struct attribute in case OnExit sub interrupts it while uninterruptible.
  531.     int Priority;  // This thread's priority relative to others.
  532.     DWORD LastError; // The result of GetLastError() after the most recent DllCall or Run.
  533.     GuiEventType GuiEvent; // This thread's triggering event, e.g. DblClk vs. normal click.
  534.     DWORD EventInfo; // Not named "GuiEventInfo" because it applies to non-GUI events such as clipboard.
  535.     POINT GuiPoint; // The position of GuiEvent. Stored as a thread vs. window attribute so that underlying threads see their original values when resumed.
  536.     GuiIndexType GuiWindowIndex, GuiControlIndex; // The GUI window index and control index that launched this thread.
  537.     GuiIndexType GuiDefaultWindowIndex; // This thread's default GUI window, used except when specified "Gui, 2:Add, ..."
  538.     GuiIndexType DialogOwnerIndex; // This thread's GUI owner, if any. Stored as Index vs. HWND to insulate against the case where a GUI window has been destroyed and recreated with a new HWND.
  539.     #define THREAD_DIALOG_OWNER ((g.DialogOwnerIndex < MAX_GUI_WINDOWS && g_gui[g.DialogOwnerIndex]) \
  540.         ? g_gui[g.DialogOwnerIndex]->mHwnd : NULL) // Above line relies on short-circuit eval. oder.
  541.     int WinDelay;  // negative values may be used as special flags.
  542.     int ControlDelay; // negative values may be used as special flags.
  543.     int KeyDelay;     //
  544.     int KeyDelayPlay; //
  545.     int PressDuration;     // The delay between the up-event and down-event of each keystroke.
  546.     int PressDurationPlay; // 
  547.     int MouseDelay;     // negative values may be used as special flags.
  548.     int MouseDelayPlay; //
  549.     char FormatFloat[32];
  550.     Func *CurrentFunc; // v1.0.46.16: The function whose body is currently being processed at load-time, or being run at runtime (if any).
  551.     Label *CurrentLabel; // The label that is currently awaiting its matching "return" (if any).
  552.     HWND hWndLastUsed;  // In many cases, it's better to use GetValidLastUsedWindow() when referring to this.
  553.     //HWND hWndToRestore;
  554.     int MsgBoxResult;  // Which button was pressed in the most recent MsgBox.
  555.     HWND DialogHWND;
  556.  
  557.     // All these one-byte members are kept adjacent to make the struct smaller, which helps conserve stack space:
  558.     SendModes SendMode;
  559.     DWORD PeekFrequency; // DWORD vs. UCHAR might improve performance a little since it's checked so often.
  560.     DWORD CalledByIsDialogMessageOrDispatchMsg; // Detects that fact that some messages (like WM_KEYDOWN->WM_NOTIFY for UpDown controls) are translated to different message numbers by IsDialogMessage (and maybe Dispatch too).
  561.     bool CalledByIsDialogMessageOrDispatch; // Helps avoid launching a monitor function twice for the same message.  This would probably be okay if it were a normal global rather than in the g-struct, but due to messaging complexity, this lends peace of mind and robustness.
  562.     bool TitleFindFast; // Whether to use the fast mode of searching window text, or the more thorough slow mode.
  563.     bool DetectHiddenWindows; // Whether to detect the titles of hidden parent windows.
  564.     bool DetectHiddenText;    // Whether to detect the text of hidden child windows.
  565.     bool AllowThreadToBeInterrupted;  // Whether this thread can be interrupted by custom menu items, hotkeys, or timers.
  566.     bool AllowTimers; // v1.0.40.01 Whether new timer threads are allowed to start during this thread.
  567.     bool ThreadIsCritical; // Whether this thread has been marked (un)interruptible by the "Critical" command.
  568.     UCHAR DefaultMouseSpeed;
  569.     UCHAR CoordMode; // Bitwise collection of flags.
  570.     UCHAR StringCaseSense; // On/Off/Locale
  571.     bool StoreCapslockMode;
  572.     bool AutoTrim;
  573.     bool FormatIntAsHex;
  574.     bool MsgBoxTimedOut; // Doesn't require initialization.
  575.     bool IsPaused, UnderlyingThreadIsPaused; // The latter supports better toggling via "Pause" or "Pause Toggle".
  576. };
  577.  
  578. inline void global_clear_state(global_struct &g)
  579. // Reset those values that represent the condition or state created by previously executed commands
  580. // but that shouldn't be retained for future threads (e.g. SetTitleMatchMode should be retained for
  581. // future threads if it occurs in the auto-execute section, but ErrorLevel shouldn't).
  582. {
  583.     g.CurrentFunc = NULL;
  584.     g.CurrentLabel = NULL;
  585.     g.hWndLastUsed = NULL;
  586.     //g.hWndToRestore = NULL;
  587.     g.MsgBoxResult = 0;
  588.     g.IsPaused = false;
  589.     g.UnderlyingThreadIsPaused = false;
  590.     g.UninterruptedLineCount = 0;
  591.     g.DialogOwnerIndex = MAX_GUI_WINDOWS; // Initialized to out-of-bounds.
  592.     g.CalledByIsDialogMessageOrDispatch = false; // CalledByIsDialogMessageOrDispatchMsg doesn't need to be cleared because it's value is only considered relevant when CalledByIsDialogMessageOrDispatch==true.
  593.     g.GuiDefaultWindowIndex = 0;
  594.     // Above line is done because allowing it to be permanently changed by the auto-exec section
  595.     // seems like it would cause more confusion that it's worth.  A change to the global default
  596.     // or even an override/always-use-this-window-number mode can be added if there is ever a
  597.     // demand for it.
  598.     g.mLoopIteration = 0; // Zero seems preferable to 1, to indicate "no loop currently running" when a thread first starts off.  This should probably be left unchanged for backward compatibility (even though script's aren't supposed to rely on it).
  599.     g.mLoopFile = NULL;
  600.     g.mLoopRegItem = NULL;
  601.     g.mLoopReadFile = NULL;
  602.     g.mLoopField = NULL;
  603. }
  604.  
  605. inline void global_init(global_struct &g)
  606. // This isn't made a real constructor to avoid the overhead, since there are times when we
  607. // want to declare a local var of type global_struct without having it initialized.
  608. {
  609.     // Init struct with application defaults.  They're in a struct so that it's easier
  610.     // to save and restore their values when one hotkey interrupts another, going into
  611.     // deeper recursion.  When the interrupting subroutine returns, the former
  612.     // subroutine's values for these are restored prior to resuming execution:
  613.     global_clear_state(g);
  614.     g.SendMode = SM_EVENT;  // v1.0.43: Default to SM_EVENT for backward compatibility.
  615.     g.TitleMatchMode = FIND_IN_LEADING_PART; // Standard default for AutoIt2 and 3.
  616.     g.TitleFindFast = true; // Since it's so much faster in many cases.
  617.     g.DetectHiddenWindows = false;  // Same as AutoIt2 but unlike AutoIt3; seems like a more intuitive default.
  618.     g.DetectHiddenText = true;  // Unlike AutoIt, which defaults to false.  This setting performs better.
  619.     // Not sure what the optimal default is.  1 seems too low (scripts would be very slow by default):
  620.     g.LinesPerCycle = -1;
  621.     g.IntervalBeforeRest = 10;  // sleep for 10ms every 10ms
  622.     #define DEFAULT_PEEK_FREQUENCY 5
  623.     g.PeekFrequency = DEFAULT_PEEK_FREQUENCY; // v1.0.46. See comments in ACT_CRITICAL.
  624.     g.AllowThreadToBeInterrupted = true; // Separate from g_AllowInterruption so that they can have independent values.
  625.     g.AllowTimers = true;
  626.     g.ThreadIsCritical = false;
  627.     #define PRIORITY_MINIMUM INT_MIN
  628.     g.Priority = 0;
  629.     g.LastError = 0;
  630.     g.GuiEvent = GUI_EVENT_NONE;
  631.     g.EventInfo = NO_EVENT_INFO;
  632.     g.GuiPoint.x = COORD_UNSPECIFIED;
  633.     g.GuiPoint.y = COORD_UNSPECIFIED;
  634.     // For these, indexes rather than pointers are stored because handles can become invalid during the
  635.     // lifetime of a thread (while it's suspended, or if it destroys the control or window that created itself):
  636.     g.GuiWindowIndex = MAX_GUI_WINDOWS;   // Default them to out-of-bounds.
  637.     g.GuiControlIndex = NO_CONTROL_INDEX; //
  638.     g.GuiDefaultWindowIndex = 0;
  639.     g.WinDelay = 100;
  640.     g.ControlDelay = 20;
  641.     g.KeyDelay = 10;
  642.     g.KeyDelayPlay = -1;
  643.     g.PressDuration = -1;
  644.     g.PressDurationPlay = -1;
  645.     g.MouseDelay = 10;
  646.     g.MouseDelayPlay = -1;
  647.     #define DEFAULT_MOUSE_SPEED 2
  648.     #define MAX_MOUSE_SPEED 100
  649.     #define MAX_MOUSE_SPEED_STR "100"
  650.     g.DefaultMouseSpeed = DEFAULT_MOUSE_SPEED;
  651.     g.CoordMode = 0;  // All the flags it contains are off by default.
  652.     g.StringCaseSense = SCS_INSENSITIVE;  // AutoIt2 default, and it does seem best.
  653.     g.StoreCapslockMode = true;  // AutoIt2 (and probably 3's) default, and it makes a lot of sense.
  654.     g.AutoTrim = true;  // AutoIt2's default, and overall the best default in most cases.
  655.     strcpy(g.FormatFloat, "%0.6f");
  656.     g.FormatIntAsHex = false;
  657.     // For FormatFloat:
  658.     // I considered storing more than 6 digits to the right of the decimal point (which is the default
  659.     // for most Unices and MSVC++ it seems).  But going beyond that makes things a little weird for many
  660.     // numbers, due to the inherent imprecision of floating point storage.  For example, 83648.4 divided
  661.     // by 2 shows up as 41824.200000 with 6 digits, but might show up 41824.19999999999700000000 with
  662.     // 20 digits.  The extra zeros could be chopped off the end easily enough, but even so, going beyond
  663.     // 6 digits seems to do more harm than good for the avg. user, overall.  A default of 6 is used here
  664.     // in case other/future compilers have a different default (for backward compatibility, we want
  665.     // 6 to always be in effect as the default for future releases).
  666. }
  667.  
  668. #define ERRORLEVEL_SAVED_SIZE 128 // The size that can be remembered (saved & restored) if a thread is interrupted. Big in case user put something bigger than a number in g_ErrorLevel.
  669.  
  670. #endif
  671.